﻿package 
{
	
	import flash.display.MovieClip;
	import flash.display.FrameLabel;
	import flash.events.*;
	
	
	public class GameDoc extends MovieClip{
		static public const MENU:String = "menu";
		static public const GAME:String = "game";
		static public const END:String = "end";
		
		function GameDoc(){
			//setup frames of main movie to send an event when they are reached
			enumerateFrameLabels();
			addEventListener(MENU, setupMenu,false,0,true);
			addEventListener(GAME, setupGame,false,0,true);
			addEventListener(END, setupEnd,false,0,true);
		}
		
		// function to dispatch an event on each labelled frame
		private function dispatchFrameEvent():void{
			stop();
			dispatchEvent(new Event(currentLabel));
		}
		private function enumerateFrameLabels():void{
			// Loop through all the labels in this movie and add a frame script to them 
			// that is the function dispatchFrameEvent
			for each (var label:FrameLabel in currentLabels)
				addFrameScript(label.frame-1, dispatchFrameEvent);
		}
		
		function setupMenu(e:Event){
			trace("setupMenu");
			test_button.button_text.text = "Start";
			test_button.addEventListener(MouseEvent.CLICK, aClick,false,0,true);
		}
		
		function setupGame(e:Event){
			end_button.button_text.text = "Win";
			end_button.addEventListener(MouseEvent.CLICK, bClick,false,0,true);
			
		}
		function setupEnd(e:Event){
			start_button.button_text.text = "Menu";
			start_button.addEventListener(MouseEvent.CLICK, cClick,false,0,true);
			
		}
		function aClick(e:Event){
			gotoAndPlay(GAME);
		}
		function bClick(e:Event){
			gotoAndPlay(END);
		}
		function cClick(e:Event){
			gotoAndPlay(MENU);
		}
		
	}
}